﻿using Md.Api.Entity.DapperModels.MdDB;

namespace Md.Dapper.Repositories.Md;
/// <summary>
/// 体验产品关联仓储
/// </summary>
public class MdProductExperienceRep : BaseRep<MdProductExperienceModel>
{
    private static string sqlFields = string.Format(@"
        `id`,
        `product_id`,
        `experience_id`
    ");

    /// <summary>
    /// 根据产品编号获取体验产品编号列表
    /// </summary>
    /// <param name="productId">产品编号</param>
    /// <returns>IEnumerable<MdProductExperienceModel></returns>
    public IEnumerable<MdProductExperienceModel> GetMdProductExperienceIdsByProductId(long productId)
    {
        string sqlWhere = string.Empty;

        #region ===where===
        if (productId > 0)
        {
            sqlWhere += " and `product_id` = @ProductId ";
        }
        #endregion

        return QueryList(sqlFields, sqlWhere, new { ProductId = productId });
    }

    /// <summary>
    /// 通过编号删除体验产品
    /// </summary>
    /// <param name="productId">产品编号</param>
    /// <returns>int</returns>
    public int DeleteMdProductExperienceByProductId(long productId)
    {
        string sqlWhere = " and `product_id` = @ProductId ";

        return Delete(sqlWhere, new { ProductId = productId });
    }
}
